const express = require('express');
const router = express.Router();
const notice = require('../../bin/control/noticeControl');
module.exports =
    router.post('/addNotice', function (req, res, next) { // 插入文章
      console.log(req.body)
       notice.addNotice(req.body)
       res.send('success')
    });

    router.get('/allNotice', function (req, res, next) { // 查询文章
      notice.findAllNotice((allData)=>{
       for(let i in allData){
          allData[i].number = parseInt(i)+1
       }
         res.send(allData)
      })
   });
   router.get('/OneNotice', function (req, res, next) { // 查询单个文章
      let _id = req.query._id
      notice.findOneNotice(_id,(allData)=>{
         res.send(allData)
      })
   //    console.log(req.body)
   });
   router.post('/deleteNotice', function (req, res, next) { // 删除文章
      let _id = req.body._id
      notice.deleteOneNotice(_id,(allData)=>{
         res.send('删除成功')
      })
   });
   router.post('/editorNotice', function (req, res, next) { // 更新文章
      console.log(req.body)
      let _id = req.body._id
      let data = req.body
      delete data._id;
      notice.updateNotice(_id, data, (allData) => {
         res.send(allData)
      })
   });
   router.post('/lookNotice',(req,res,next)=>{
      let userId = req.body.userId;
      let noticeId = req.body.noticeId;
      notice.driverLook(userId,noticeId,()=>{
         res.send('浏览成功')
      })
   })
      
